package br.com.felipeab.dexter.faces;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

public class GenericDataModel<T extends Serializable> extends ListDataModel<T> implements SelectableDataModel<T> {

	public GenericDataModel() {

	}

	public GenericDataModel(List<T> list) {
		super(list);
	}

	public Object getRowKey(T object) {
		return object;
	}

	@SuppressWarnings("unchecked")
	public T getRowData(String rowKey) {
		List<T> list = (List<T>) getWrappedData();
		for (T item : list) {
			if (item.equals(rowKey)) {
				return item;
			}
		}
		return null;
	}

}
